﻿using _80X_CG_Frame.Windows;
using _80X_CG_Frame.Workers;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace _80X_CG_Frame
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        MainWindow window;
        
        /// <summary>
        /// 应用程序启动事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnStartup(StartupEventArgs e)
        {
            //暂时取消重复关闭
            CloseMultiProcess();
            Login login = new Login();
            window = new MainWindow();
            login.ShowDialog();
            if (login.DialogResult.Value)
            {
                //global.mainWindow = window;
                window.Show();

            }
            else
            {
                window.Close();
                GLOBAL.StopAll();
            }

        }
        /// <summary>
        /// 仅允许开启一个应用窗口(关闭多开程序)
        /// </summary>
        private void CloseMultiProcess()
        {
            Process process = Process.GetCurrentProcess();
            if (Process.GetProcessesByName(process.ProcessName).Count() > 1)
                this.Shutdown();
        }
        protected override void OnExit(ExitEventArgs e)
        {
            GLOBAL.StopAll();
        }
    }
}
